package tianrun.ziguan.api.calculate.config.config.web;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.function.Predicate;

@EnableSwagger2
@Configuration
public class SwaggerConfig {
    @Value("${spring.application.name:API}")
    private String title;

    public SwaggerConfig() {
    }

    @Bean
    public Docket createRestApi() {
        Predicate<RequestHandler> predicate = (input) -> input.isAnnotatedWith(ApiOperation.class) && (input.isAnnotatedWith(GetMapping.class) || input.isAnnotatedWith(PostMapping.class));
        ApiInfo apiInfo = (new ApiInfoBuilder()).title(this.title).build();
        ApiSelectorBuilder var10000 = (new Docket(DocumentationType.SWAGGER_2)).forCodeGeneration(true).select();
        return var10000.apis(predicate::test).build().apiInfo(apiInfo).enableUrlTemplating(true);
    }
}
